<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="js/vue.js"></script>
    <script src="js/axios.min.js"></script>
    <title>装备市场</title>
    <style>
        body {
            background-color: #121212;
            color: #e0e0e0;
            font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            position: relative;
            min-height: 100vh;
            background-image: url('images/csgo2.jpg'); /* 背景图 */
            background-size: cover; /* 使背景图覆盖整个页面 */
            background-position: center center; /* 背景图居中 */
            background-attachment: fixed; /* 背景图固定，滚动页面时不会移动 */
        }

        h1 {
            text-align: center;
            color: #aa9bf9;
            font-size: 2rem;
            margin-bottom: 20px;
        }

        .category-bar {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }

        .category-button {
            background-color: #007BFF;
            color: white;
            padding: 12px 20px;
            border-radius: 20px;
            border: none;
            cursor: pointer;
            transition: background-color 0.3s;
            font-size: 1rem;
        }

        .category-button:hover,
        .category-button.active {
            background-color: #0056b3;
        }

        .category-button:focus {
            outline: none;
        }

        .search-bar {
            text-align: center;
            margin-top: 1rem;
        }

        .search-bar input {
            padding: 0.5rem 1rem;
            width: 250px;
            border-radius: 20px;
            border: 1px solid #ccc;
            outline: none;
            margin-right: 10px;
            background-color: #333;
            color: #fff;
        }

        .search-bar button {
            background-color: #007BFF;
            color: white;
            padding: 0.5rem 1rem;
            border-radius: 20px;
            border: none;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .search-bar button:hover {
            background-color: #0056b3;
        }

        .equipment-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }

        .equipment-item {
            background-color: rgba(0, 0, 0, 0.7); /* 设置黑色半透明背景 */
            border: 1px solid #444;
            border-radius: 10px;
            padding: 15px;
            text-align: center;
            transition: box-shadow 0.3s;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .equipment-item:hover {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }

        .equipment-item img {
            width: 100%;
            height: auto;
            border-radius: 5px;
            margin-bottom: 10px;
        }

        .equipment-item h3 {
            margin: 10px 0;
            color: #ffffff;
            font-size: 1.2rem;
        }

        .equipment-item p {
            color: #ccc;
            font-size: 0.9rem;
        }

        .equipment-item a {
            text-decoration: none;
            color: inherit;
        }

        .equipment-item a:hover h3 {
            text-decoration: underline;
        }

        .saveOrderBtn {
            background-color: #28a745;
            color: white;
            padding: 12px 24px;
            border-radius: 30px;
            border: none;
            font-size: 16px;
            margin-top: 20px;
            cursor: pointer;
            width: 100%;
            transition: background-color 0.3s ease;
        }

        .saveOrderBtn:hover {
            background-color: #218838;
        }

        /* 返回主页按钮样式 */
        .back-home-btn {
            position: fixed;
            top: 20px;
            left: 20px;
            background-color: #aa9bf9;
            color: #121212;
            padding: 10px 18px;
            border-radius: 6px;
            font-weight: 700;
            text-decoration: none;
            font-size: 16px;
            z-index: 1000;
            transition: background-color 0.3s ease;
        }

        .back-home-btn:hover {
            background-color: #8c7ee6;
        }

        /* 右上角用户模块 */
        .login-link, .register-link, .user-link {
            position: fixed;
            top: 20px;
            background-color: #aa9bf9;
            color: #121212;
            padding: 10px 20px;
            font-weight: 700;
            font-size: 16px;
            border-radius: 6px;
            text-decoration: none;
            transition: background-color 0.3s ease;
            z-index: 1000;
            display: inline-block;
        }
        .login-link:hover, .register-link:hover, .user-link:hover {
            background-color: #8c7ee6;
        }
        .login-link { right: 100px; }
        .register-link { right: 20px; }
        .user-link { right: 20px; cursor: pointer; }
    </style>
</head>
<body>
<a href="/ffub/main.html" class="back-home-btn">返回主页</a>

<div id="topLinks">
    <!-- Vue渲染登录/注册或用户名 -->
</div>

<h1>饰品市场</h1>

<div id="app">
    <nav class="category-bar">
        <button class="category-button" @click="getAllequipments" :class="{ active: currentCategory === '全部' }">全部</button>
        <span v-for="(type, index) in typeList" :key="index">
        <button class="category-button" @click="getByType(type.typeId)" :class="{ active: currentCategory === type.typeName }">
          {{ type.typeName }}
        </button>
      </span>
    </nav>

    <div class="search-bar">
        <input type="text" v-model="searchKeyword" placeholder="请输入道具名称进行搜索" />
        <button @click="searchEquipment">搜索</button>
    </div>

    <div class="equipment-list">
        <div v-for="equipment in equipmentList" :key="equipment.equipmentId" class="equipment-item">
            <a :href="'equipment_detail.html?id=' + equipment.equipmentId">
                <img :src="equipment.equipmentImage" alt="装备图片" />
                <h3>{{ equipment.equipmentName }}</h3>
                <p>价格: ¥{{ equipment.equipmentPrice }}</p>
                <p>类型: {{ equipment.equipmentType }}</p>
                <p>稀有度: {{ equipment.rarity }}</p>
                <p>磨损度: {{ equipment.exterior }}</p>
            </a>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#topLinks',
        data() {
            return {
                userName: localStorage.getItem('userName') || ''
            }
        },
        template: `
          <div>
          <a v-if="!userName" href="login.html" class="login-link">登录</a>
          <a v-if="!userName" href="register.html" class="register-link">注册</a>
          <a v-if="userName" href="user.html" class="user-link">{{ userName }}</a>
          </div>
        `
    });

    const vm = new Vue({
        el: "#app",
        data: {
            equipmentList: [],
            typeList: [],
            currentCategory: '全部',
            searchKeyword: ''
        },
        mounted() {
            this.getAllequipments();
            this.getAllTypes();
        },
        methods: {
            getAllequipments() {
                axios.get("equipment").then(res => {
                    this.equipmentList = res.data.data;
                });
            },
            getAllTypes() {
                axios.get("equipmentType").then(res => {
                    this.typeList = res.data.data;
                });
            },
            getByType(typeId) {
                axios.get("equipment/type/" + typeId).then(res => {
                    this.equipmentList = res.data.data;
                    const selected = this.typeList.find(t => t.typeId === typeId);
                    this.currentCategory = selected ? selected.typeName : '';
                });
            },
            searchEquipment() {
                const keyword = this.searchKeyword.trim();
                if (!keyword) {
                    alert("请输入搜索关键词");
                    return;
                }
                axios.get("equipment/name/" + encodeURIComponent(keyword)).then(res => {
                    this.equipmentList = res.data.data;
                    this.currentCategory = '';
                });
            }
        }
    });
</script>
</body>
</html>
